$(function () {
  // 获取url中code值
  function getUrlParams (name) {
    var search = document.location.search
    var pattern = new RegExp('[?&]' + name + '\=([^&]+)', 'g')
    var matcher = pattern.exec(search)
    var items = null
    if (null != matcher) {
      try {
        items = decodeURIComponent(decodeURIComponent(matcher[1]))
      } catch (e) {
        try {
          items = decodeURIComponent(matcher[1])
        } catch (e) {
          items = matcher[1]
        }
      }
    }
    return items
  }
  var orders_no = getUrlParams('order_Sn');
  var price = getUrlParams('price');
  var goodsId = $.cookie('goodsId');
  $('.price').text('￥' + price);
  var notify_url = '';
  param = 'orders_no='+orders_no+'&total_fee='+price+'&subject=爆品&return_url="./paySuccess.html?"&notify_url=';
  //   判断浏览器类型
  if (/MicroMessenger/.test(window.navigator.userAgent)) {
    // 微信中
    notify_url = 'http://h5.scsj.net.cn/wxpay/notify_url_bp.php';
    param+=notify_url;
    $('.wx').show();
    $('.wx a').attr('href', 'http://h5.scsj.net.cn/wxpay/inwxpay_common.php?' + param)
  } else if (/AlipayClient/.test(window.navigator.userAgent)) {
    // 支付宝 
    $('.ali').show()
    notify_url = 'http://h5.scsj.net.cn/alipay/alipay-trade/notify_url_bp.php'
    param+=notify_url;
    $('.ali a').attr('href', 'http://h5.scsj.net.cn/alipay/alipay-trade/alipay_common.php?' + param)
  } else {
    //   普通浏览器
    $('.ali').show()
    $('.wx').show()
    notify_url = 'http://h5.scsj.net.cn/alipay/alipay-trade/notify_url_bp.php'
    param+=notify_url;
    // 普通浏览器下需发送请求
    
      $.ajax({
        type: 'post',
        url: 'http://h5.scsj.net.cn/wxpay/wxh5_common.php',
        data: {'orders_no': orders_no,'total_fee': price,'subject': '爆品', 'return_url': './paySuccess.html','notify_url': 'http://h5.scsj.net.cn/wxpay/notify_url_bp.php'},
        success: function (data) {
          $('.wx a').attr('href', data.url);
        },error: function () {
          $("body").toast({content:'系统错误'})
        }

      })
    // 支付宝直接跳转
    $('.ali a').attr('href', 'http://h5.scsj.net.cn/alipay/alipay-trade/alipay_common.php?' + param)
  }
})
